#ifndef H_DEF
#define H_DEF

#include "Arduino.h"

// CYCLE Min us
#define CYCLEMIN 2000
#define CYCLERATE (1e6/CYCLEMIN)

#if defined(HEXAX) || defined(HEXAP)
// Extra output channel SERVO
#define SERVO
#define SERVOFAST // normally 50hz servo mode if you enable this you get 500hz update
#endif

// SetState constant
#define CALIBRATE 1
#define BLINKNORMAL 0
#define BLINKARMED 1
#define BLINKFAST 2

#define ISIN60 (1/0.8660254)
#define ISIN45 (1/0.7071068)

// channel from receiver are [-1;1] between 1000-2000 us
#define CHDOWN -0.7
#define CHUP    0.7
#define CHLEFT -0.7
#define CHRIGHT 0.7


typedef union 
{
  struct 
  {
    float x,y,z;
  } 
  vector;
  struct 
  {
    float r,p,y;
  } 
  rotate;
  float val[3];
} 
v3d;

// CHECK Section
/////////////////////////////////////////////////////////////////////////////////////

#ifdef CAMSTAB

#if !defined(GYRO_PRESENT) || !defined(ACC_PRESENT) 
#error Can't drive a CAMSTAB without ACC
#endif

#define SERVO
#undef SERVOFAST
#define A0_A1_PIN_HEX

#endif

#if defined(SERVO) && !defined(PPMSUM) && !defined(A0_A1_PIN_HEX)
#error Channel D5 D6 cannot be used by the Receiver
#endif


int limit(int mn,int v,int mx)
{
  if (v<mn) return mn;
  if (v>mx) return mx;
  return v;
}

float limitf(float mn,float v,float mx)
{
  if (v<mn) return mn;
  if (v>mx) return mx;
  return v;
}

#endif



